/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.simba.utils.tree;

/**
 *
 * @author ngonga
 */
public class DependencyReader {

    public static Tree getDependencies(String dependencies) {
        Tree result = new Tree();
        String lines[] = dependencies.split("\n");
        String split[];
        String d;
        String edgeType;
        for (int i = 0; i < lines.length; i++) {
            if (lines[i].contains("(") && lines[i].contains(")")) {
                edgeType = lines[i].substring(0, lines[i].indexOf("("));
                d = lines[i].substring(lines[i].indexOf("(") + 1, lines[i].lastIndexOf(")"));
                split = d.split(", ");
                result.addEdge(split[0], split[1], edgeType);
            }
        }
        return result;
    }

    public static void main(String args[]) {

//           nsubj(happy-4, SAP-1)
//                cop(happy-4, is-2)
//               advmod(happy-4, really-3)
//               aux(receive-6, to-5)
//                xcomp(happy-4, receive-6)
//                det(grant-8, this-7)
//                dobj(receive-6, grant-8)
        
        
        
//    In the short term, the Arab Spring is very  unfavorable, but for the longer term, these countries have to develop  and energy is a key element of development.    
//        
//        det(term-4, the-2)
//amod(term-4, short-3)
//prep_in(unfavorable-11, term-4)
//det(Spring-8, the-6)
//nn(Spring-8, Arab-7)
//nsubj(unfavorable-11, Spring-8)
//cop(unfavorable-11, is-9)
//advmod(unfavorable-11, very-10)
//root(ROOT-0, unfavorable-11)
//det(term-17, the-15)
//amod(term-17, longer-16)
//prep_for(have-21, term-17)
//det(countries-20, these-19)
//nsubj(have-21, countries-20)
//xsubj(develop-23, countries-20)
//conj_but(unfavorable-11, have-21)
//aux(develop-23, to-22)
//xcomp(have-21, develop-23)
//nsubj(element-29, energy-25)
//cop(element-29, is-26)
//det(element-29, a-27)
//amod(element-29, key-28)
//conj_and(unfavorable-11, element-29)
//prep_of(element-29, development-31)
        

        String s = "nsubj(happy-4, SAP-1)\n"
                + "cop(happy-4, is-2)\n"
                + "advmod(happy-4, really-3)\n"
                + "aux(receive-6, to-5)\n"
                + "xcomp(happy-4, receive-6)\n"
                + "det(grant-8, this-7)\n"
                + "dobj(receive-6, grant-8)\n";

        Tree t = getDependencies(s);
        System.out.println(t.edges);
        Sentiment sent = new Sentiment();
        Double score = sent.getSentiment(s, "SAP", "subject");
        System.out.println("sentiment of SAP: " + score);

    }
}
